package base.utils

import android.app.Activity
import android.content.Context
import android.view.inputmethod.InputMethodManager
import android.widget.EditText

/**
 * Created by jjw on 2018/5/18 0018.
 */
class KeyboardUtils {
    companion object {
        /**
         * 隐藏键盘
         */
        fun hideSoftKeyboard(editText: EditText?, context: Context?) {
            if (editText != null && context != null) {
                val imm = context
                        .getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
                imm.hideSoftInputFromWindow(editText.windowToken, 0)
            }
        }

        /**
         * 显示键盘
         */
        fun showSoftKeyboard(editText: EditText?, context: Context?) {
            if (editText != null && context != null) {
                val imm = context
                        .getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
                imm.showSoftInput(editText, 0)
            }
        }
    }

}